package com.itheima.fiter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;


//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {

    @Override //初始化方法，只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
        System.out.println("init实现了");
    }

    @Override //拦截请求之后调用。调用多次
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("doFilter拦截了请求,放行之前逻辑");
//        放行
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("doFilter放行了请求,放行后前逻辑");
    }

    @Override   //销毁的方法，只调用一次
    public void destroy() {
        Filter.super.destroy();
        System.out.println("destroy销毁了");
    }
}
